#include "client.h"
#include "command.h"
#include "protocol.h"
#include <sys/socket.h>
#include "../include/transfer.h"
#include "../include/protocol.h"        
#include "../include/command.h"         
#define MMAP_THRESHOLD (100*1024*1024)  

int reiceive(int netfd){
    TLVMsg msg;
    printf("服务端:\n"); 
    recvfd(netfd,&msg);
    //printf("%s\n",msg.value);
    /* printf("msg.type=%d\n",msg.type); */ 
    /* printf("msg.valu=%s\n",msg.value); */
    /* printf("msg.value_len =%d\n",msg.value_len); */
    /* printf("服务端:\n"); */ 
    int ret=msg.type;
    switch (ret){    
    case CMD_INVALID:    //无效
        printf("%s\n",msg.value);
        break;
    case CMD_CD:       //切换目录
        printf("%s\n",msg.value) ; 
        break;
    case CMD_LS:      //列出目录下文件
        printf("%s\n",msg.value);
        break;
    case CMD_PUTS://上传文件 
        transfile(msg.value,netfd);
        recvfd(netfd,&msg);
        printf("%s\n",msg.value);
        break;
    case CMD_GETS:   //下载文件
        recvfile(netfd);
        break;
    case CMD_REMOVE:   //删除文件
        printf("%s\n",msg.value);
        break;
    case CMD_PWD:     //显示路径
        printf("%s\n",msg.value);
        break;
    case CMD_MKDIR:   //创建目录
        printf("%s\n",msg.value);
        break;
    case CMD_LOGIN:     //登录
        printf("%s\n",msg.value);
        int flat=0;
        while(!flat){
            printf("请输入账户:\n");
            flat=enter(netfd); 
        }
        printf("请输入指令:\n"); 
        break;
    case CMD_LOGOUT:   //退出登录
        flat=0;
        while(!flat){
            printf("请输入账户:\n");
            flat=enter(netfd); 
        }  
        break;
    case CMD_QUIT:    //退出
        printf("退出成功，请重新打开软件\n");
        exit(0);
    case CMD_RMDIR:   //删除目录
        printf("%s\n",msg.value);
        break;
    case CMD_RESUME:
        recvfile(netfd);
        break;   
    }
    return 0;
}

